import { addWorkConnect } from './workConnect.config.js'
import { vendorsFmtDate, vendorsDanger, } from 'utils/config.js';
import { getPrintCodeByType } from 'utils/netRequest.js';
import moment from 'moment';

let tenantId;
let cookieStr = document.cookie.split(';').find(cur => cur.indexOf('tenantid=') != -1)
if (cookieStr) {
    tenantId = cookieStr.split('=')[1];
}

tenantId = tenantId || 'x61tnmfx';


export default function buttonClick(params) {
    console.log(params)
    switch (params.key) {
        case 'listadd':
            this.props.router.push({ pathname: '/card', state: { cardState: 'add', pk: '' } })
            break;
        case 'save':
            let validateFormResult = this.props.form.validateForm();
            if (validateFormResult.length != 0) {
                vendorsDanger({ 'text': validateFormResult.join(',') + '为必输项' });
                return;
            }
            let formData = this.props.form.collectFormValue();
            formData["billType"] = "GZLX";
            formData.pkTenant = tenantId;
            addWorkConnect.call(this, formData,
                res => {
                    let { result, resultCode } = res.data;
                    if (resultCode == 'ok') {
                        this.setState({
                            cardState: 'browse',
                            pk: result.pk_workconnect,
                        })
                        this.setFormValueWithResult(result);
                    } else {

                    }
                },
                error => {
                    console.log(error);
                }
            );
            break;
        case 'cancel':
            this.props.router.replace('/list');
            break;
        case 'add':
            this.setState({
                cardState: 'add',
                pk: '',
            })
            this.props.form.clearFormValue({});
            break;
        case 'attachment':
            this.ygcUpload.open();
            break;
        case 'listattachment':
            if (this.state.selectRows.length == 0) {
                this.props.vendorsWarning({ text: '请选择数据!' });
                return;
            }
            this.ygcUpload.open();
            break;
        case 'listprint':
            if (this.state.selectRows.length == 0) {
                this.props.vendorsWarning({ text: '请选择数据!' });
                return;
            }
            getPrintCodeByType({
                tenantId: tenantId,
                billType: 'GZLX',
                pkBill: this.state.selectRows[0]['pk_workconnect'],
                // pkProcess: this.state.pk,
            })
            break;
        case 'print':
            getPrintCodeByType({
                tenantId: tenantId,
                billType: 'GZLX',
                pkBill: this.state.pk,
                // pkProcess: this.state.pk,
            })
            break;
        case 'approve':
            this.props.passreject.initPassRejectModal({ record: this.state.formData, page: 'card', primaryKey: 'pk_workconnect' });
            break;
        case 'refresh':
            if (this.props.location.pathname == "/card") {
                this.getPageData();
            } else {
                let { selectedS } = this.props.search.getSearchData();
                this.searchBtnClick.call(this, selectedS, { type: 'refresh' });
            }
            break;
        case 'listReceiveDes':
            if (this.state.selectRows.length == 0) {
                this.props.vendorsWarning({ text: '请选择数据!' });
                return;
            }
            this.setState({
                isAcceptShow: true,
                modalType: 'detail',
                pk_workconnect: this.state.selectRows[0]['pk_workconnect'],
            });
            break;
        case 'receiveDes':
            this.setState({
                isAcceptShow: true,
                modalType: 'detail',
                pk_workconnect: this.state.pk,
            });
            break;
        case 'accept':
            this.setState({
                isAcceptShow: true,
                modalType: 'accept',
            })
            break;
        default:
            break;
    }
}

